// Base on: QHHCV2

#include "TTS_Speech.h"

bool TTS_Speech::begin(Stream &stream) {

  _serial = &stream;
}

void TTS_Speech::play(uint8_t coding,String text){
  int text_len = text.length() + 2;
  _serial->write(0xFD);
  _serial->write(text_len >> 8);
  _serial->write(text_len);
  _serial->write(0x01);
  _serial->write(coding);
  _serial->print(text);

  // Serial.write(0xFD);
  // Serial.write(text_len >> 8);
  // Serial.write(text_len);
  // Serial.write(0x01);
  // Serial.write(coding);
  // Serial.print(text);

}


void TTS_Speech::playMode(uint8_t type) {
  byte FS_array[] = {0xFD, 0x00, 0x01, 0x00};
  FS_array[3] = type;
  for (int i = 0; i < 4; i++) {
    _serial->write(FS_array[i]);
  }
}
